package com.jxmcloud.business.cut.service.impl.logic;

import com.jxmcloud.business.cut.model.database.DBUserGiveUpAwardConfig;
import com.jxmcloud.business.cut.model.database.DBUserInviteSuccess;
import com.jxmcloud.business.cut.service.database.IUserGiveUpAwardConfigDBService;
import com.jxmcloud.business.cut.service.database.IUserInviteSuccessDBService;
import com.jxmcloud.business.cut.service.logic.IUserGiveUpHandle;
import com.jxmcloud.business.cut.vo.user.PlayerInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserGiveUPHandleImpl implements IUserGiveUpHandle {
    @Autowired
    private IUserInviteSuccessDBService userInviteSuccessDBService;
    @Autowired
    private IUserGiveUpAwardConfigDBService userGiveUserAwardConfigDBService;

    @Override
    public DBUserGiveUpAwardConfig checkUserGiveUpAward(PlayerInfoVo player) {
        // 1. 获取用户实际助理人数
        List<DBUserInviteSuccess> inviteSuccesses = userInviteSuccessDBService.selectAll(player.getBase().getUid(),player.getActivity().getActivityId());
        List<DBUserGiveUpAwardConfig> userGiveUpAwardConfigs = userGiveUserAwardConfigDBService.getBaseMapper().selectList(null);
        // 按照inviteNum进行倒序排序
        userGiveUpAwardConfigs.sort((a, b) -> b.getInviteNum() - a.getInviteNum());
        for (DBUserGiveUpAwardConfig userGiveUpAwardConfig : userGiveUpAwardConfigs) {
            if (inviteSuccesses.size() >= userGiveUpAwardConfig.getInviteNum()) {
                return userGiveUpAwardConfig;
            }
        }
        return null;
    }
}
